package mybatistestpak;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
 

 
import com.google.common.collect.Maps;

import mybatistestpak.utl.paramReqUtil;

 
@SuppressWarnings("all")
public class MybatisTest2 {

	public static void main(String[] args) throws SQLException {
	 
		//移动医生站\hodoctor\src\mybatistestpak\mybatis.xml
		MybatisSessionFactory.CONFIG_FILE_LOCATION = "C:\\0wkspc\\移动医疗源码\\移动医护\\移动医生站\\hodoctor\\src\\mybatistestpak/mybatis.xml";
		SqlSession session = MybatisSessionFactory.getSession();
		
		//  Map<String,Object> paramMap = new HashMap<String, Object>();
		  String urlparams="VAA07=55975&DocumentId=0&DeptId=23&AAG01=1&EmpId=244&Type=4&VAA01=82767&BCK01=21&ACF01=2&VAP01=0";
		
		Map  paramMap=  paramReqUtil.  urlQuerystr2map(urlparams);
	List<Map> li=	session.selectList("VCF1.getBinliFiletype",  paramMap);
	for (Map m : li) {
		String caption=(String) m.get("Caption");
		String caption2_gbk2utf8=strService.gbk2utf8(caption);
		String caption2_utf2gbk=strService.utf2gbk(caption);
		String caption2_iso2gbk=strService.iso2gbk(caption);
		 System.out.println("d");
	}
		System.out.println(li.size());
		System.out.println(li);
		System.out.println("--");
	}

	 
	Connection conn;
	public   Connection get_conn() {

		SqlSession session = getSqlSession();
		  conn = session.getConnection();
return conn;
	 
	}
	
	protected static Statement getStt() {

		SqlSession session = getSqlSession();
		Connection conn = session.getConnection();

		Statement st = null;
		try {
			conn.setAutoCommit(true);
			st = conn.createStatement();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		return st;
	}

	private static SqlSession getSqlSession() {
		MybatisSessionFactory.CONFIG_FILE_LOCATION = "/com/attilax/db/mybatisutil/mybatis_postgresql.xml";
		SqlSession session = MybatisSessionFactory.getSession();
		return session;
	}

	private static String getTrueSql(String sql, Map<String, Object> m) {
		for (Map.Entry entry : m.entrySet()) {
			String key = (String) entry.getKey();
			key = key.trim();
			System.out.println(key + ":" + entry.getValue());

			sql = sql.replaceAll("\\#\\{" + key + "\\}", getValueByTypeinSql(entry.getValue()));
		}
		return sql;
	}

	private static String getValueByTypeinSql(Object value) {
		if (value.getClass() == String.class)
			return "'" + value.toString() + "'";
		if (value.getClass() == Integer.class)
			return value.toString();
		throw new RuntimeException("getValueByTypeinSql:: value not jude type");
	}

	 

}
